package com.college.eduService.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.api.R;
import com.college.commonutil.result.Result;
import com.college.eduService.client.CommentClient;
import com.college.eduService.entity.EduCourse;
import com.college.eduService.entity.EduTeacher;
import com.college.eduService.service.EduCourseService;
import com.college.eduService.service.EduTeacherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
@RequestMapping("/eduservice/indexFront")
public class IndexFrontController {

    @Autowired
    private EduCourseService eduCourseService;

    @Autowired
    private EduTeacherService eduTeacherService;


    //查询前8条热门课程，查询前4个名师
    @GetMapping("/index")
    public Result index(){
        //查询前8条热门课程
        List<EduCourse> courseList = eduCourseService.selectHotCourse();
        //查询前4张名师
        List<EduTeacher> teacherList = eduTeacherService.selectHotTeacher();

        return Result.ok().data("courseList",courseList).data("teacherList",teacherList);
    }
    //每次观看视频修改播放量
    @GetMapping("/viewcount/{courseId}")
    public void viewCount(@PathVariable String courseId){
        EduCourse course=eduCourseService.getById(courseId);
        if(course!=null) {
            if (course.getViewCount() == null) {
                course.setViewCount(0L);
            }
            course.setId(courseId);
            course.setViewCount(course.getViewCount() + 1L);
            eduCourseService.updateById(course);
        }
    }
}
